
// Source File Name:   RTO_MO_PQImpl.java

package com.sunwayhorizo.health.hl7.datatypes.common;

import com.sunwayhorizo.health.hl7.common.VersionInfo;
import com.sunwayhorizo.health.hl7.datatypes.ANY;
import com.sunwayhorizo.health.hl7.datatypes.BL;
import com.sunwayhorizo.health.hl7.datatypes.CS;
import com.sunwayhorizo.health.hl7.datatypes.MO;
import com.sunwayhorizo.health.hl7.datatypes.PQ;
import com.sunwayhorizo.health.hl7.datatypes.QTY;
import com.sunwayhorizo.health.hl7.datatypes.RTO_MO_PQ;
import com.sunwayhorizo.health.hl7.datatypes.ST;
import com.sunwayhorizo.health.hl7.datatypes.TYPE;

// Referenced classes of package oracle.apps.ctb.hl7.types.common:
//            ANYImpl, BLImpl, CSImpl, MOImpl, 
//            PQImpl, REALImpl, STImpl, TYPEImpl

public class RTO_MO_PQImpl extends ANYImpl
    implements RTO_MO_PQ
{

    private static final String ZERO = "0";
    private static final String ONE = "1";
    private static final String RATIO_SEPARATOR = ":";
    private MO mNumerator;
    private PQ mDenominator;
    private static final RTO_MO_PQ nullNI = new RTO_MO_PQImpl(CSImpl.valueOf("NI"));
    private static final RTO_MO_PQ nullOTH = new RTO_MO_PQImpl(CSImpl.valueOf("OTH"));
    private static final RTO_MO_PQ nullNINF = new RTO_MO_PQImpl(CSImpl.valueOf("NINF"));
    private static final RTO_MO_PQ nullPINF = new RTO_MO_PQImpl(CSImpl.valueOf("PINF"));
    private static final RTO_MO_PQ nullUNK = new RTO_MO_PQImpl(CSImpl.valueOf("UNK"));
    private static final RTO_MO_PQ nullASKU = new RTO_MO_PQImpl(CSImpl.valueOf("ASKU"));
    private static final RTO_MO_PQ nullNAV = new RTO_MO_PQImpl(CSImpl.valueOf("NAV"));
    private static final RTO_MO_PQ nullMSK = new RTO_MO_PQImpl(CSImpl.valueOf("MSK"));
    private static final RTO_MO_PQ nullNA = new RTO_MO_PQImpl(CSImpl.valueOf("NA"));
    private static final RTO_MO_PQ nullNASK = new RTO_MO_PQImpl(CSImpl.valueOf("NASK"));

    public static RTO_MO_PQ valueOf(MO mo, PQ pq)
    {
        return new RTO_MO_PQImpl(mo, pq);
    }

    public static RTO_MO_PQ nullRTO_MO_PQ()
    {
        return new RTO_MO_PQImpl(null);
    }

    protected RTO_MO_PQImpl(MO mo, PQ pq)
    {
        if(mo == null || mo.isNull().isTrue())
            mNumerator = MOImpl.valueOf(REALImpl.valueOf("1"), CSImpl.nullCS());
        else
            mNumerator = mo;
        if(pq == null || pq.isNull().isTrue())
            mDenominator = PQImpl.valueOf(REALImpl.valueOf("1"), CSImpl.valueOf("1"));
        else
            mDenominator = pq;
//        if(mDenominator.value().equal(REALImpl.valueOf("0")).isTrue())
//            throw ANYImpl.newRatioException("RTO<MO,PQ>");
//        else
//            return;
    }

    protected RTO_MO_PQImpl()
    {
        mNumerator = MOImpl.valueOf(REALImpl.valueOf("1"), null);
        mDenominator = PQImpl.valueOf(REALImpl.valueOf("1"), null);
    }

    protected RTO_MO_PQImpl(CS cs)
    {
        super(true, cs);
        mNumerator = MOImpl.nullMO(cs);
        mDenominator = PQImpl.nullPQ(cs);
    }

    public BL equal(ANY any)
    {
        if(!(any instanceof RTO_MO_PQ))
            return BLImpl.FALSE;
        if(isNull().or(any.isNull()).isTrue())
        {
            return BLImpl.FALSE;
        } else
        {
            RTO_MO_PQ rto_mo_pq = (RTO_MO_PQ)any;
            return BLImpl.valueOf(mNumerator.equal(rto_mo_pq.numerator()).and(mDenominator.equal(rto_mo_pq.denominator())).isTrue());
        }
    }

    public TYPE dataType()
    {
        return com.sunwayhorizo.health.hl7.datatypes.common.TYPEImpl.RTO_MO_PQ;
    }

    public BL lessOrEqual(QTY qty)
    {
        throw ANYImpl.newUnsupportedException("RTO<MO_PQ>", "lessOrEqual");
    }

    public BL compares(QTY qty)
    {
        throw ANYImpl.newUnsupportedException("RTO<MO_PQ>", "compares");
    }

    public TYPE diffType()
    {
        return com.sunwayhorizo.health.hl7.datatypes.common.TYPEImpl.RTO_MO_PQ;
    }

    public QTY minus(QTY qty)
    {
        throw ANYImpl.newUnsupportedException("RTO<MO_PQ>", "minus");
    }

    public QTY plus(QTY qty)
    {
        throw ANYImpl.newUnsupportedException("RTO<MO_PQ>", "plus");
    }

    public BL isZero()
    {
        throw ANYImpl.newUnsupportedException("RTO<MO_PQ>", "isZero");
    }

    public BL lessThan(QTY qty)
    {
        throw ANYImpl.newUnsupportedException("RTO<MO_PQ>", "lessThan");
    }

    public BL greaterOrEqual(QTY qty)
    {
        throw ANYImpl.newUnsupportedException("RTO<MO_PQ>", "greaterOrEqual");
    }

    public BL greaterThan(QTY qty)
    {
        throw ANYImpl.newUnsupportedException("RTO<MO_PQ>", "greaterThan");
    }

    public ST literal()
    {
        StringBuffer stringbuffer = new StringBuffer();
        if(mNumerator.isNull().isTrue())
            stringbuffer.append("0");
        else
            stringbuffer.append(mNumerator.literal().stringValue());
        stringbuffer.append(":");
        if(mDenominator.isNull().isTrue())
            stringbuffer.append("1");
        else
            stringbuffer.append(mDenominator.literal().stringValue());
        return STImpl.valueOf(stringbuffer.toString());
    }

    public MO numerator()
    {
        return mNumerator;
    }

    public PQ denominator()
    {
        return mDenominator;
    }

    public int hashCode()
    {
        int i = 17;
        if(isNull().isFalse())
        {
            i = 37 * i + numerator().hashCode();
            i = 37 * i + denominator().hashCode();
        }
        return i;
    }

    public static RTO_MO_PQ nullRTO_MO_PQ(CS cs)
    {
        String s = null;
        if(cs == null || cs.literal().stringValue() == null || cs.isNull().isTrue())
            s = "NI";
        else
            s = cs.literal().stringValue();
        if(s.equals("NI"))
            return nullNI;
        if(s.equals("OTH"))
            return nullOTH;
        if(s.equals("NINF"))
            return nullNINF;
        if(s.equals("PINF"))
            return nullPINF;
        if(s.equals("UNK"))
            return nullUNK;
        if(s.equals("ASKU"))
            return nullASKU;
        if(s.equals("NAV"))
            return nullNAV;
        if(s.equals("MSK"))
            return nullMSK;
        if(s.equals("NA"))
            return nullNA;
        if(s.equals("NASK"))
            return nullNASK;
        else
            return nullNI;
    }

}
